package com;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;

public class Backgroud {
    Image image;
    int y1=0;//背景的y坐标
    int y2 = -2048;
    int step = 5;
    public Backgroud(){
        //把图片读取进来
        //image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("images/map.jpg"));
        image = ImageIOUtils.getImage(this,"images/map.jpg");
    }
    public void draw(Graphics graphics) {
        //将背景画出来
        graphics.drawImage(image,0,this.y1,null);
        //让背景动起来
        this.y1=this.y1+step;

        //若果图片消失，补充到后边去
        graphics.drawImage(image,0,this.y2,null);
        this.y2=this.y2+step;
        if(this.y1 >= 2048){
            this.y1 = 0;
        }
        if(this.y2>=0){
            this.y2 = -2048;
        }
    }
}
